﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data;
using System.Data.Common;
using BOHVote.Core;

namespace BOHVote.DAL
{
    public class NotifyProivde
    {
        Database db;
        public NotifyProivde()
        {
            db = DatabaseFactory.CreateDatabase();
        }

        #region <<  Notify Info  >>

        #region <<  Select   >>
        public DataSet getAllNotify(string NotifyTitle, string NotifyID, string NotifyVerify, string NotifyStatus, string NotifyType)
        {
            string strSQL = "SELECT * FROM ApplyNotify WHERE 1=1  ";
            if (!string.IsNullOrEmpty(NotifyTitle))
            {
                strSQL += " AND Notify_title like '%" + NotifyTitle + "%'";
            }
            if (!string.IsNullOrEmpty(NotifyID))
            {
                strSQL += " AND Notify_id = '" + NotifyID + "'";
            }
            if (!string.IsNullOrEmpty(NotifyVerify))
            {
                strSQL += " AND Notify_Verify = '" + NotifyVerify + "'";
            }
            if (!string.IsNullOrEmpty(NotifyStatus))
            {
                strSQL += " AND Notify_status = '" + NotifyStatus + "'";
            }
            if (!string.IsNullOrEmpty(NotifyType))
            {
                strSQL += " AND Notify_Type = '" + NotifyType + "' ";
            }

            strSQL += " ORDER  BY Notify_issueTime ASC";


            DbCommand dbcommand = db.GetSqlStringCommand(strSQL);

            return Utility.ExecuteDataSet(db, dbcommand);
        }
        #endregion

        #region <<  Update  >>
        public int UpdateNotify(string NotifyID, string NotifyTitle, string NotifyVerify, string NotifyStatus, string NotifyContext, string UserID, string NotifyType)
        {
            string strSQL = "UPDATE ApplyNotify SET Notify_title ='" + NotifyTitle + "',Notify_Verify = '" + NotifyVerify + "',Notify_Context = '" + NotifyContext + "',Notify_status = '" + NotifyStatus + "',Notify_issueTime = getdate(),UserID='" + UserID + "' WHERE Notify_id='" + NotifyID + "' AND Notify_Type='" + NotifyType + "'";
            DbCommand dbcommand = db.GetSqlStringCommand(strSQL);

            return Utility.ExecuteNonQuery(db, dbcommand);
        }
        #endregion

        #region <<  Insert  >>
        public int InsertNotify(string NotifyTitle, string NotifyVerify, string NotifyStatus, string NotifyContext, string UserID, string NotifyType)
        {
            string strSQL = "INSERT INTO ApplyNotify(Notify_title,Notify_Verify,Notify_Context,Notify_status,Notify_issueTime,UserID,Notify_Type)VALUES('" + NotifyTitle + "','" + NotifyVerify + "','" + NotifyContext + "','" + NotifyStatus + "',getdate(),'" + UserID + "','" + NotifyType + "')";
            DbCommand dbcommand = db.GetSqlStringCommand(strSQL);

            return Utility.ExecuteNonQuery(db, dbcommand);
        }
        #endregion

        #region <<  Delete  >>
        public int DeleteNotify(string NotifyID, string NotifyType)
        {
            string strSQL = "DELETE FROM ApplyNotify WHERE Notify_id =" + NotifyID + " AND Notify_Type = '" + NotifyType + "'";
            DbCommand dbcommand = db.GetSqlStringCommand(strSQL);

            return Utility.ExecuteNonQuery(db, dbcommand);
        }
        #endregion

        #endregion
    }
}
